package com.ruoyi.client.controller;

import com.ruoyi.client.pojo.vo.HomeCarouselVo;
import com.ruoyi.client.pojo.vo.HomeGoodsVo;
import com.ruoyi.client.pojo.vo.HomeInfoVo;
import com.ruoyi.client.service.ClientHomeService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 首页接口
 */
@Anonymous //允许匿名访问
@Api(tags = "1-首页接口")
@RestController
@RequestMapping("/home")
public class ClientHomeController extends BaseController {

    @Resource
    ClientHomeService clientHomeService;  //注入服务层 Bean

    @ApiOperation("获取首页数据")
    @GetMapping("/index")
    public R<HomeInfoVo> index() {
        HomeInfoVo homeInfoVo = new HomeInfoVo(); // 首页数据

        List<HomeCarouselVo> carouselVoList = clientHomeService.selectCarouseVoList(); //调用首页服务层获取轮播数据列表
        List<HomeGoodsVo> recommendGoodsVoList = clientHomeService.selectRecommendGoodsVoList(); //调用首页服务层获取首页推荐商品数据列表

        homeInfoVo.setCarouselList(carouselVoList); // 封装轮播数据
        homeInfoVo.setRecommendGoodsList(recommendGoodsVoList); // 封装推荐商品数据
        return R.ok(homeInfoVo);
    }
}
